const express = require('express')
const bodyParser = require('body-parser')
const app = express()

// app.use((req, res, next) => {
//   if(req.headers["content-type"] === 'application/json'){
//     req.on('data', (data) => {
//       const info = JSON.parse(data.toString())
//       req.body = info
//     })
//     req.on('end', () =>{
//       next()
//     })
//   }else{
//     next()
//   }
// })

app.use(express.json())
app.use(express.urlencoded({extended:true}))
app.post('/login', (req, res, next) => {
  console.log(req.body)
  res.end('login')
})

app.post('/product', (req, res, next) => {
  console.log(req.body)
  res.end('product')
})

app.listen(8000, (req, res, next) => {
  console.log('服务器启动成功')
})

//body-parser